package cn.edu.ldu.protocol;

import cn.edu.ldu.modules.controller.UserAccountController;
import cn.edu.ldu.modules.entity.UserAccountEntity;
import cn.edu.ldu.util.Consts;
import cn.edu.ldu.views.modules.controller.UserController;
import com.alibaba.fastjson.JSONObject;

public class GetFriendAccount {

    public GetFriendAccount(Protocol protocol){

        Long userId = Long.valueOf(JSONObject.parseObject(protocol.getData()).getString("id"));

        try {
            UserAccountEntity userAccountEntity = UserAccountController.getUserAccount(userId, protocol.getToken());
            if(userAccountEntity != null){
                protocol.setData(JSONObject.toJSONString(userAccountEntity));
                protocol.setKey(Consts.P_FRIEND_RESULT);
                UserController.sendDataToUser(protocol);
            }else {
                protocol.setKey("不存在该用户");
                protocol.setData(null);
                UserController.sendDataToUser(protocol);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
